home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
bioinformatics.org
/
bioinformatics.org_software.tar
/
www.bioinformatics.org
/
download
/
ecell2
/
ecell220setup.exe
/
{app}
/
standard
/
SRCJ
/
Substance.java
< prev
next >
Wrap
Text File
|
2002-05-13
|
15KB
|
525 lines
/**
* title: Substance class (Substance.java)<p>
* description: Substance window class<p>
* Copyright (C) 1996-2001 Keio University <p>
* Copyright (C) 1998-2001 Japan Science and Technology Corporation (JST)<p>
* GNU General Public Licence <p>
* Division: Mitui Knowledge Industry Co. Ltd. Bioscience division <p>
* Version : $Id: Substance.java,v 1.7 2002/05/13 00:23:04 ota Exp $ <p>
*/
package ecell;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import javax.swing.*;
import javax.swing.plaf.basic.*;
import java.io.*;
import java.util.Vector;
/**
* Substance window class
* @author XD.Zheng
* @version 1.0
* @since JDK1.2.2
*/
/**
public class Substance extends JFrame
implements ActionListener, ItemListener, FocusListener, KeyListener, AccessListener{
**/
public class Substance extends ECell2Interface implements ItemListener, FocusListener
{
JPanel jp1 = new JPanel();
JPanel jp11 = new JPanel();
JPanel jp12 = new JPanel();
JPanel jp2 = new JPanel();
JPanel jp31 = new JPanel();
JPanel jp32 = new JPanel();
JPanel jp311 = new JPanel();
JPanel jp321 = new JPanel();
JPanel jp3 = new JPanel();
JLabel label1 = new JLabel();
JLabel label2 = new JLabel();
JLabel label3 = new JLabel("Quantity[molecules]");
JTextField txtQuantity= new JTextField(30);
JLabel label5 = new JLabel("Concentration[M]");
JTextField txtConcent = new JTextField(30);
JButton buttonP = new JButton("+");
JButton buttonM = new JButton("-");
JCheckBox checkFix = new JCheckBox("FIX");
JButton buttonClose= new JButton("Close");
Border border1;
Border border2;
Border border3;
GridLayout gridLayout1 = new GridLayout();
//boolean focusFlag1 =false;
//boolean focusFlag2 =false;
// 2002.1.22 akira shiozawa
// last value for quantity/concentration
String value_backup = "";
/**
* Instance of MainWindow
*/
//MainWindow window;
/**
* Timer to determine updating data
*/
//Timer timer = new Timer(100,this);
/**
* SubstanceWindows number
*/
int subCode =-1;
/**
*EntryName;
*/
String entryName ="";
/**
*Name;
*/
String name = "";
/**
*Constructor
*/
public Substance( int code,String entryName, String name,MainWindow window) {
super( window );
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
this.subCode =code;
this.entryName= entryName;
this.name = name;
//this.window = window;
// 2002.2.21 comment out by akira shiozawa
//int length = entryName.length();
//String str = entryName.substring(length-2,length);
jbInit();
//timer.start();
window.addAccessListener( this );
}
/**
* Initialization
* @return void
*/
public void jbInit(){
this.setResizable(true);
border1 = BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED,Color.white,Color.white,new Color(142, 142, 142),new Color(99, 99, 99)),BorderFactory.createEmptyBorder(0,3,0,3));
border2 = BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED,Color.white,Color.white,new Color(99, 99, 99),new Color(142, 142, 142)),BorderFactory.createEmptyBorder(0,3,0,3));
border3 = BorderFactory.createBevelBorder(BevelBorder.RAISED,Color.white,Color.white,new Color(142, 142, 142),new Color(99, 99, 99));
//this.setSize(new Dimension(350, 200));
this.setSizeAndLocation(new Dimension(350, 200), new Point(150, 100) );
this.setTitle("Substance: " + entryName);
buttonClose.addActionListener(this);
buttonP.addActionListener(this);
buttonM.addActionListener(this);
jp11.setLayout(new FlowLayout(0,5,2));
buttonClose.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED,Color.white,Color.white,new Color(142, 142, 142),new Color(99, 99, 99)),BorderFactory.createEmptyBorder(2,5,2,5)));
label1.setForeground(Color.black);
label2.setForeground(Color.black);
buttonP.setFont(new java.awt.Font("DialogInput", 1, 12));
buttonP.setForeground(SystemColor.activeCaption);
buttonP.setBorder(border2);
buttonM.setFont(new java.awt.Font("DialogInput", 1, 12));
buttonM.setForeground(SystemColor.activeCaption);
buttonM.setBorder(border1);
jp2.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED,Color.white,Color.white,new Color(142, 142, 142),new Color(99, 99, 99)));
jp31.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED,Color.white,Color.white,new Color(142, 142, 142),new Color(99, 99, 99)));
jp32.setBorder(border3);
txtQuantity.addFocusListener(this);
// 2002.1.23 akira shiozawa
txtQuantity.addKeyListener( myKeyAdapter );
//txtQuantity.setForeground(SystemColor.desktop);
//txtQuantity.setForeground(Color.lightGray);
txtQuantity.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED,Color.white,Color.white,new Color(142, 142, 142),new Color(99, 99, 99)),BorderFactory.createEmptyBorder(0,10,0,0)));
txtQuantity.setHorizontalAlignment(SwingConstants.LEFT);
txtConcent.addFocusListener(this);
// 2002.1.23 akira shiozawa
txtConcent.addKeyListener( myKeyAdapter );
//txtConcent.setForeground(SystemColor.desktop);
//txtConcent.setForeground(Color.lightGray);
txtConcent.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED,Color.white,Color.white,new Color(142, 142, 142),new Color(99, 99, 99)),BorderFactory.createEmptyBorder(0,10,0,0)));
label3.setFont(new java.awt.Font("Dialog", 3, 12));
label3.setForeground(Color.black);
label3.setBorder(BorderFactory.createEmptyBorder(0,10,0,0));
label5.setFont(new java.awt.Font("Dialog", 3, 12));
label5.setForeground(Color.black);
label5.setBorder(BorderFactory.createEmptyBorder(0,10,0,0));
jp11.add(checkFix);
checkFix.addActionListener(this);
jp12.setLayout(new FlowLayout(2,15,2));
jp12.add(buttonClose);
jp1.setLayout(new BorderLayout());
jp1.add(jp11,"West");
jp1.add(jp12,"East");
this.getContentPane().add(jp1,"North");
label1.setText(" Entry name: "+ entryName);
label2.setText(" Name : "+ name);
jp2.setLayout(new GridLayout(2,1,0,10));
jp2.add(label1);
jp2.add(label2);
jp3.add(jp31, null);
jp31.add(label3);
jp31.add(txtQuantity);
jp31.add(jp311);
jp311.add(buttonP);
jp311.add(buttonM);
jp3.add(jp32, null);
jp32.add(label5);
jp32.add(txtConcent);
jp31.setLayout(new GridLayout(3,1,17,0));
jp32.setLayout(new GridLayout(3,1,1,0));
jp3.setLayout(gridLayout1);
this.getContentPane().add(jp2,"Center");
this.getContentPane().add(jp3,"South");
// 2002.4 akira shiozawa
getSubstanceData();
}
/**
* Event of ActionEvent
* @param e ActionEvent
* @return void
*/
public void actionPerformed(ActionEvent e) {
//System.out.println( "actionPerformed" );
if(e.getSource()== buttonClose){
exit_actionPerformed();
}
/**
else if(e.getSource()== timer){
if(subCode>= 0 ){
double[] data = new double[3];
int count = window.count;
try{
window.df.getSubstanceData(count,subCode,data);
}catch(Exception ex){
ex.printStackTrace();
}
if(focusFlag1==false){
txtQuantity.setText(" "+ getDoubleValue(data[0]));
}
if(focusFlag2==false){
txtConcent.setText(" "+ getDoubleValue(data[1]));
}
if(data[2]==0.0){
checkFix.setSelected(false);
}else{
checkFix.setSelected(true);
}
}
}
**/
else if(e.getSource() == buttonP){
try{
window.df.setJniChange(subCode,1);
}catch(Exception ex){
window.messageWindow.setErrorMessage( ex );
}
this.getSubstanceData();
}
else if(e.getSource() == buttonM) {
try{
window.df.setJniChange(subCode,-1);
}catch(Exception ex){
window.messageWindow.setErrorMessage( ex );
}
this.getSubstanceData();
}
else if(e.getSource() == checkFix){
try{
window.df.setSubstanceFix( subCode,checkFix.isSelected());
}catch(Exception ex){
window.messageWindow.setErrorMessage( ex );
}
this.getSubstanceData();
}
}
/**
* Event
* @param evt ItemEvent
* @return void
*/
public void itemStateChanged(ItemEvent evt){
try{
window.df.setSubstanceFix( subCode,checkFix.isSelected());
}catch(Exception ex){
window.messageWindow.setErrorMessage( ex );
}
}
/**
* Event
* @param win MainWindow
* @return void
*/
public void accessJni( MainWindow win )
{
setRunningFlag( true );
this.getSubstanceData();
setRunningFlag( false );
}
private void getSubstanceData()
{
if(subCode>= 0 )
{
double[] data = new double[3];
int count = window.count;
try
{
window.df.getSubstanceData(count,subCode,data);
}
catch(Exception ex)
{
window.messageWindow.setErrorMessage( ex );
}
//if(focusFlag1==false){
if( !txtQuantity.hasFocus() )
{
txtQuantity.setText(" "+ getDoubleValue(data[0]));
}
//if(focusFlag2==false)
if( !txtConcent.hasFocus() )
{
txtConcent.setText(" "+ getDoubleValue(data[1]));
}
if(data[2]==0.0)
{
checkFix.setSelected(false);
}
else
{
checkFix.setSelected(true);
}
}
}
/**
* Override to exit when the window is closed.
* @param e WindowEvent
* @return void
*/
/**
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
//System.out.println( "processWindowEvent" );
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
exit_actionPerformed();
}
}
**/
// 2002.4 akira shiozawa
KeyAdapter myKeyAdapter = new KeyAdapter()
{
public void keyPressed( KeyEvent e )
{
if( e.getKeyCode() == KeyEvent.VK_ESCAPE )
{
JTextField dst = (JTextField)e.getSource();
dst.setText( value_backup );
}
}
};
/**
* Exit
* @return void
*/
public void exit_actionPerformed(){
//System.out.println( "Substance exit" );
//timer.stop();
// 2002.4. akira shizoawa
window.removeAccessListener( this );
try{
window.df.setSubstanceState(subCode,-1);
}catch(Exception ex){
window.messageWindow.setErrorMessage( ex );
}
this.setVisible(false);
/**
Vector vs = window.vSubstance;
for(int i=0;i<vs.size();i++){
if(this==vs.elementAt(i)){
vs.remove(i);
//this.dispose();
}
}
**/
this.dispose();
}
/**
* focusGained event
* @param e FocusEvent
* @return void
*/
public void focusGained(FocusEvent e){
//System.out.println( "focusGained" );
value_backup = ((JTextField)e.getSource()).getText();
/**
if(e.getSource()==txtQuantity){
//focusFlag1=true;
txtQuantity_backup = txtQuantity.getText();
}
if(e.getSource()==txtConcent){
//focusFlag2=true;
txtConcent_backup = txtConcent.getText();
}
**/
}
/**
* forcusLost event
* @param e FocusEvent
* @return void
*/
public void focusLost(FocusEvent e) {
double data =0.0;
// 2002.4 akira shiozawa
boolean changed = false;
String input_value = ((JTextField)e.getSource()).getText();
if( !input_value.equals( value_backup ) )
{
try
{
changed = true;
data = Double.parseDouble( input_value );
window.df.setSubstanceText( subCode, ((e.getSource() == txtConcent)? 1 : 0), data );
}
catch( Exception ex )
{
window.messageWindow.setErrorMessage( ex );
}
}
/**
// 2002.1.23 akira shiozawa
boolean changed = false;
if(e.getSource()==txtQuantity){
try{
if( !txtQuantity.getText().equals( txtQuantity_backup ) )
{
changed = true;
data=Double.parseDouble(txtQuantity.getText());
//System.out.println( "quantity text:" + data );
window.df.setSubstanceText(subCode,0,data);
}
}catch(Exception ex){
}
//focusFlag1=false;
}
if(e.getSource()==txtConcent){
try{
if( !txtConcent.getText().equals( txtConcent_backup ) )
{
changed = true;
data=Double.parseDouble(txtConcent.getText());
//System.out.println( "concentration text:" + data );
window.df.setSubstanceText(subCode,1,data);
}
}catch(Exception ex){
}
//focusFlag2=false;
}
**/
// 2002.1.23 akira shiozawa
if( changed )
{
double[] value = new double[3];
try{
window.df.getSubstanceData(window.count,subCode,value);
}
catch(Exception ex)
{
window.messageWindow.setErrorMessage( ex );
}
txtQuantity.setText(" "+ getDoubleValue(value[0]));
txtConcent.setText(" "+ getDoubleValue(value[1]));
}
}
/**
* Convert Double value to suitable String one.
* @param vaule Double data
* @return Converted String
*/
public String getDoubleValue(double value){
int dotIndex=-1;
int eIndex=-1;
String str=String.valueOf(value);
//System.out.println( "str:" + str + ",double:" + value );
int len=str.length();
if(len<=8) return str;
dotIndex=str.indexOf(".");
eIndex=str.indexOf("E");
if(eIndex==-1){
if(dotIndex==-1){
return str;
}else if(dotIndex==7){
return str.substring(0,9);
}else if(dotIndex<7){
return str.substring(0,8);
}else if(dotIndex>7){
return str.substring(0,dotIndex);
}
}else if(eIndex<=7){
return str;
}else{
return (str.substring(0,7)+str.substring(eIndex,len));
}
return "";
}
}